package oa.org.oa.ishchenko;

public class StringUtils {
	public static String reverse (String str1){
		return new StringBuilder(str1).reverse().toString();

	}
	
	public static Boolean isPalindrome(String str2) {
		String b = str2.replaceAll(" ", "");
        return b.equalsIgnoreCase(reverse (b));
    }
	
	public static String replaceWord (String str3){
		str3 = str3.trim();
		String [] mass1 = str3.split(" ");
		String[] mass2 = new String[mass1.length];
		System.arraycopy(mass1, 0, mass2, 0, mass1.length);
		mass2[0] = mass1[mass1.length - 1]; 
		mass2[mass2.length-1] = mass1[0];
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < mass2.length; i++) {
			builder.append(mass2[i]);
			builder.append(" ");
			
		}
		
		return builder.toString().trim();
		
		
	}
	
	public static String replaceWordInProposal(String str4){
		String [] mass = str4.split("\\.");
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < mass.length; i++) {
			String str = StringUtils.replaceWord(mass[i]);
			builder.append(str);
			builder.append(". ");
			
		}
		return builder.toString().trim();
	}
}
